<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

<html>
<head>
    <title>用户列表</title>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=basePath%>css/navigation.css" rel="stylesheet" type="text/css" />
    <script type="<%=basePath%>text/javascript" src="js/jquery.js"></script>

    <%--function authority1(username) {--%>
    <%--    location.href="<%=basePath%>updateauthority1?id="+username;--%>
    <%--}--%>
    <%--function authority2(username) {--%>
    <%--    location.href="<%=basePath%>updateauthority2?id="+username;--%>
    <%--}--%>

    <script type="text/javascript">
        $(document).ready(function(){
            $(".click").click(function(){
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function(){
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function(){
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function(){
                $(".tip").fadeOut(100);
            });

        });
        function UpdateAuthority1(id){
            if(confirm('确认要更改选择的用户吗？')){
                location.href="<%=basePath%>updateauthority1?id="+id;

            }
        }
        function UpdateAuthority2(id){
            if(confirm('确认要更改选择的用户吗？')){
                location.href="<%=basePath%>updateauthority2?id="+id;

            }
        }
        function DeleteByid(id){
            if(confirm('确认要删除选择的用户吗？')){
                location.href="<%=basePath%>deleteByid?id="+id;
            }
        }
    </script>

</head>
<body>
<div class="container">

    <div class="row">
        <div class="col-md-12">
            <h1 align="center">用户查看</h1>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover table-striped ">
                <tr>
                    <th><strong>用户名</strong></th>
                    <th><strong>真名</strong></th>
                    <th><strong>密码</strong></th>
                    <th><strong>性别</strong></th>
                    <th><strong>年龄</strong></th>
                    <th><strong>地址</strong></th>
                    <th><strong>经度</strong></th>
                    <th><strong>纬度</strong></th>
                    <th><strong>权限</strong></th>
                    <th><strong>操作</strong></th>

                </tr>
                <c:forEach items="${pageInfo.list}" var="user">
                    <tr>
                        <th>${user.username}</th>
                        <th>${user.realname}</th>
                        <th>${user.password}</th>
                        <th>${user.gender}</th>
                        <th>${user.age}</th>
                        <th>${user.address_place}</th>
                        <th>${user.lng}</th>
                        <th>${user.lat}</th>
                        <th>${user.p_identity == 1?"普通用户":"管理员"}</th>
                        <td>
                            <button type="button" class="btn btn-primary" onclick="UpdateAuthority1(${user.id})">普通用户</button>
                            <button type="button" class="btn btn-danger"  onclick="UpdateAuthority2(${user.id})" >管理员用户</button>
                            <button type="button" class="btn btn-danger"  onclick="DeleteByid(${user.id})" >删除</button>
                        </td>
                    </tr>
                </c:forEach>

            </table>
            <div class="box">
                <div id="pagination" class="page center">
                </div>
            </div>

        </div>
        <div class="row">
            <%--           分页文字信息--%>
            <div class="col-md-6">
                当前${pageInfo.pageNum}页,总共${pageInfo.pages}页,共${pageInfo.total}条记录
            </div>

            <div class="col-md-6">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li><a href="<%=basePath%>findAllUser?pn=1">首页</a></li>

                        <c:if test="${pageInfo.hasPreviousPage}">
                            <li>
                                <a href="<%=basePath%>findAllUser?pn=${pageInfo.pageNum-1}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        </c:if>

                        <c:forEach items="${pageInfo.navigatepageNums}" var="page_Num">
                            <c:if test="${page_Num == pageInfo.pageNum}">
                                <li class="active"><a href="#">${page_Num }</a></li>
                            </c:if>
                            <c:if test="${page_Num != pageInfo.pageNum}">
                                <li><a href="<%=basePath%>findAllUser?pn=${page_Num }">${page_Num }</a></li>
                            </c:if>

                        </c:forEach>

                        <c:if test="${pageInfo.hasNextPage}">
                            <li> <a href="<%=basePath%>findAllUser?pn=${pageInfo.pageNum+1 }" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a></li>
                        </c:if>

                        <li><a href="<%=basePath%>findAllUser?pn=${pageInfo.pages}">末页</a></li>
                    </ul>
                </nav>
            </div>

        </div>
    </div>



</body>
</html>
